package com.xupt.easy.array;

import com.sun.deploy.util.StringUtils;

/**
 * @author zhaoxin
 * @title: DayOfTheWeek
 * @projectName LeetCode
 * @description: 1185. 一周中的第几天
 * @date 2020/1/6 11:19
 */
public class DayOfTheWeek {


    /**
     * 给你一个日期，请你设计一个算法来判断它是对应一周中的哪一天。
     *
     * 输入为三个整数：day、month 和 year，分别表示日、月、年。
     *
     * 您返回的结果必须是这几个值中的一个 {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}。
     *
     *  
     *
     * 示例 1：
     *
     * 输入：day = 31, month = 8, year = 2019
     * 输出："Saturday"
     * 示例 2：
     *
     * 输入：day = 18, month = 7, year = 1999
     * 输出："Sunday"
     * 示例 3：
     *
     * 输入：day = 15, month = 8, year = 1993
     * 输出："Sunday"
     *  
     *
     * 提示：
     *
     * 给出的日期一定是在 1971 到 2100 年之间的有效日期。
     *
     * @param day
     * @param month
     * @param year
     * @return
     */
    public String dayOfTheWeek(int day, int month, int year) {
        // 核心算法: 【蔡勒公式】或【基姆拉尔森计算公式】
        if (month == 1){
            month = 13;
            year--;
        }
        if (month == 2){
            month = 14;
            year--;
        }

        int week = (day + 2*month + 3*(month + 1) /5 + year + year/4 - year/100 + year/400) %7;
        String weekStr = "";
        switch (week){
            case 6:
                weekStr = "Sunday";
                break;
            case 0:
                weekStr = "Monday";
                break;
            case 1:
                weekStr = "Tuesday";
                break;
            case 2:
                weekStr = "Wednesday";
                break;
            case 3:
                weekStr = "Thursday";
                break;
            case 4:
                weekStr = "Friday";
                break;
            case 5:
                weekStr = "Saturday";
                break;
        }
        return weekStr;
    }
}
